package com.pignest.hotel.module.income.ui.base;

import org.zkoss.zk.ui.event.Event;
import org.zkoss.zk.ui.event.EventListener;
import org.zkoss.zul.Listbox; 
import org.zkoss.zul.Paging;
import org.zkoss.zul.event.PagingEvent;

import com.pignest.hotel.util.PageResult;

@SuppressWarnings("serial")
public abstract class ListBox extends Listbox {
	public PageResult pageResult = new PageResult(); 
	private Paging pag = null ; 
	
	public void newQuery() {
		if(pageResult==null) pageResult = new PageResult(); 
		pageResult.setPageSize(pag.getPageSize());
		this.Query();
		pag.setTotalSize(pageResult.getRowCount());  
	} 
	
	
	public void onCreate() { 
		this.setHead();
		pag = this.getPaging();  
		pag.addEventListener("onPaging",this.onPaging(pag));  
		this.newQuery();
	}

	public abstract void setHead();

	public abstract Paging getPaging();

	public EventListener onPaging(final Paging pag){
		return new EventListener(){
				public void onEvent(Event event) {
					PagingEvent pe = (PagingEvent) event;  
					pageResult.setCurrentPage( pe.getActivePage()+1);
					pageResult.setPageSize( pag.getPageSize());
					Query();
				}
			} ;
	}

	public abstract void Query();
	
	public void clearRecord(){
		this.getItems().clear();
	}
	 
   
}
